package com.lean.android.projecttemplate.startup

import android.content.Context
import androidx.startup.Initializer
import com.airbnb.mvrx.Mavericks
import com.lean.android.projecttemplate.BuildConfig
import timber.log.Timber

/**
 * 通用组件初始化，优先级最高
 */
class CommonComponentInitializer : Initializer<Unit> {

    override fun create(context: Context) {
        initTimber()
        Thread.setDefaultUncaughtExceptionHandler { t, e ->
            Timber.e(e)
        }
        Timber.d("init common component.")

        Mavericks.initialize(context)
    }

    private fun initTimber() {
        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }
    }

    override fun dependencies(): List<Class<out Initializer<*>>> {
        return emptyList()
    }
}